package com.hsylient.ObserverPattern;

import java.util.ArrayList;
import java.util.List;

/**
 * 具体的通知者
 */
public class Secretary implements MySubject {

    private List<MyObserver> observers = new ArrayList<>();
    private String action;

    @Override
    public void attach(MyObserver observer) {
        observers.add(observer);
    }

    @Override
    public void detach(MyObserver observer) {
        observers.remove(observer);
    }

    @Override
    public void notifyObservers() {
        for (MyObserver observer : observers) {
            observer.update();
        }
    }

    @Override
    public void setAction(String action) {
        this.action = action;
    }

    @Override
    public String getAction() {
        return action;
    }
}
